package com.lzm.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzm.mapper.MenuMapper;
import com.lzm.pojo.Hosregister;
import com.lzm.pojo.Menu;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class menuService {

    @Resource
    private MenuMapper menuMapper;

    public PageInfo<Menu> queryByPage(Integer pageNum, Integer pageSize,String menu_name){
        //分页
        PageHelper.startPage(pageNum, pageSize);
        List<Menu> list = menuMapper.queryByName(menu_name);
        return new PageInfo<>(list);
    }

    public int addMenu(Menu menu){
        return menuMapper.insertSelective(menu);
    }
    public Menu queryById(Integer menu_id){
       Menu menu = menuMapper.selectByPrimaryKey(menu_id);
        return menu;
    }
    public int updateMenu(Menu menu){
        return menuMapper.updateByPrimaryKeySelective(menu);
    }
    public int deleteMenu(Integer menu_id){
        Menu menu = menuMapper.selectByPrimaryKey(menu_id);
       menu.setMenu_state(1);
        return menuMapper.updateByPrimaryKeySelective(menu);
    }
}
